package com.esun.cheetah.view.setting;

import android.content.Context;
import android.content.SharedPreferences;

import com.esun.cheetah.R;
import com.esun.cheetah.config.Config;

public class ValuesManager {
	/** 父信息 */
	private boolean parent = true;
	/** 铃声 */
	private boolean ring = true;
	/** 震动 */
	private boolean vibrator = true;
	/** 足球半场或者结束 */
	private boolean fbBegOrEnd = true;
	/** 足球进球 */
	private boolean goal = true;
	/** 足球红牌 */
	private boolean redCard = true;
	/** 赛前30分钟*/
	private boolean preGameThrityMinit = true;
	/** 设备Id */
	private String useName;
	/** 结束时间 */
	private String endTime;
	/** 开始时间 */
	private String beginTime;

	public String getUseName() {
		return useName;
	}

	public String getBeginTime() {
		return beginTime;
	}

	public String getEndTime() {
		return endTime;
	}

	public SharedPreferences getSharedPrefValues() {
		return sharedPrefValues;
	}

	private SharedPreferences sharedPrefValues;

	public ValuesManager(Context context) {
		this.sharedPrefValues = context.getSharedPreferences(Config.SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE);
		getValue(context);

	}

	// 获取比赛信息数组
	public boolean[] getArayValues(Context context) {
		boolean[] values = new boolean[8];
		values[1] = sharedPrefValues.getBoolean(Config.RING_PREFERENCE, true);
		values[2] = sharedPrefValues.getBoolean(Config.VIBRATOR_PREFERENCE, true);
		values[3] = sharedPrefValues.getBoolean(Config.FOOT_BEG_END_PREF, true);
		values[4] = sharedPrefValues.getBoolean(Config.FOOT_GOAL_PREF, true);
		values[5] = sharedPrefValues.getBoolean(Config.RED_CARD_PREF, true);
		values[6] = sharedPrefValues.getBoolean(Config.BEGIN_PRE_THRIT, true);
//		values[7] = sharedPrefValues.getBoolean(Config.BAS_HALF_PREF, true);
		return values;
	}

	/**
	 * 
	 * @param context
	 * @return true 还有子信息 false 没有子信息
	 */
	public boolean value(Context context) {
		boolean[] values = getArayValues(context);
		for (int i = 0; i < values.length; i++) {
			if (values[i]) {
				return true;
			}
		}
		return false;

	}

	public boolean isParent() {
		return parent;
	}

	public boolean isRing() {
		return ring;
	}

	public boolean isVibrator() {
		return vibrator;
	}

	public boolean isFbBegOrEnd() {
		return fbBegOrEnd;
	}

	public boolean isGoal() {
		return goal;
	}

	public boolean isRedCard() {
		return redCard;
	}

	public boolean isBasHalf() {
		return preGameThrityMinit;
	}

	public boolean isBasBegin() {
		return preGameThrityMinit;
	}
	
	public boolean isPreGameThrityMinit() {
		return preGameThrityMinit;
	}
	/**
	 * 获取定制比赛信息
	 * 
	 * @param context
	 */
	public void getValue(Context context) {
		parent = sharedPrefValues.getBoolean(Config.PCF, true);
		ring = sharedPrefValues.getBoolean(Config.RING_PREFERENCE, true);
		vibrator = sharedPrefValues.getBoolean(Config.VIBRATOR_PREFERENCE, false);
		fbBegOrEnd = sharedPrefValues.getBoolean(Config.FOOT_BEG_END_PREF, true);
		goal = sharedPrefValues.getBoolean(Config.FOOT_GOAL_PREF, true);
		redCard = sharedPrefValues.getBoolean(Config.RED_CARD_PREF, true);
		preGameThrityMinit = sharedPrefValues.getBoolean(Config.BEGIN_PRE_THRIT, true);
		useName = sharedPrefValues.getString(Config.XMPP_USERNAME, "");
		beginTime = sharedPrefValues.getString(Config.BEGIN_TIME, context.getString(R.string.default_begin_time));
		endTime = sharedPrefValues.getString(Config.END_TIME, context.getString(R.string.default_end_time));
	}

	/**
	 * 布尔值转换为者整数
	 * 
	 * @param b
	 * @return
	 */
	public static String covert(boolean b) {
		if (b) {
			return 1 + "";
		} else {
			return 0 + "";
		}
	}

	public static String covert(boolean ring, boolean vibrator) {
		if (ring) {
			return 0 + "";
		}
		if (vibrator) {
			return 1 + "";
		}
		return 2 + "";

	}

}
